#include "tcp_decoder.h"

TcpDecoder::TcpDecoder()
{
	pTcpHead = NULL;
	pIpHead = NULL;
}

TcpDecoder::TcpDecoder(const u_char* packetcontent)
{
	pIpHead = (struct iphdr *) (packetcontent + sizeof(struct ether_header));
	pTcpHead = (struct tcphdr *) (packetcontent + sizeof(struct ether_header)+sizeof(struct iphdr));
}

TcpDecoder::~TcpDecoder()
{
	pTcpHead = NULL;
	pIpHead = NULL;
	delete pTcpHead;
	delete pIpHead;
}

unsigned short TcpDecoder::GetSrcPort()
{
	return htons(pTcpHead->source);
}

unsigned short TcpDecoder::GetDstPort()
{
	return htons(pTcpHead->dest);
}

unsigned int TcpDecoder::GetSeqNum()
{
	return htonl(pTcpHead->seq);
}

unsigned int TcpDecoder::GetNextSeq()
{
	
	return GetSeqNum() + htons(pIpHead->tot_len) - sizeof(struct iphdr) - sizeof(struct tcphdr);
}

unsigned int TcpDecoder::GetAckNum()
{
	return htonl(pTcpHead->ack_seq);
}

unsigned int TcpDecoder::GetWindowSize()
{
	return htonl(pTcpHead->window);
}

unsigned int TcpDecoder::GetChecksum()
{
	return htonl(pTcpHead->check);
}

tcphdr* TcpDecoder::GetTcpHead()
{
	return pTcpHead;
}
